package sort;

import java.util.Arrays;

//冒泡排序
public class BubbleSort {
    public static void main(String[] args) {
//        int array[] = {1, 3, 9, 56, 87, 49, 35};
        /*  //int整型升序
        for (int i = 0; i < array.length; i++) {  //i表示比较的轮数
            for (int j = 0; j < array.length - 1 - i; j++) {  //j表示比较元素的下标
                if (array[j] > array[j + 1]) {
                    int temp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = temp;
                }
            }
        }*/

        /*  //int整型降序
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if (array[j] < array[j+1]){
                    int temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }*/
          //String数组升序
        String array[] = {"tom","张飒","aion","fuck","zuie","米恩"};
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if (array[j].compareTo(array[j+1])>0){
                    String temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(array));
    }
}
